package com.nuoniu.sibanyun.controller.project;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.project.RdTools;
import com.nuoniu.sibanyun.service.project.IRdToolsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.awt.HeadlessToolkit;

/**
 * <p>
 * 研发工具描述 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-08-06
 */
@RestController
@RequestMapping("/rd/tools")
@Api(tags = "研发工具管理")
public class RdToolsController extends BaseController {

    @Autowired
    private IRdToolsService toolsService;

    @ApiOperation("获取列表")
    @GetMapping("getList")
    public HttpResult getList(String functionMenu, Integer type,Integer projectId) {
        if(null == projectId)throw new NuoNiuException("请选择项目");
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("project_id", projectId);
        wrapper.eq("function_menu", functionMenu);
        wrapper.eq("type", type);
        return HttpResult.ok(toolsService.list(wrapper));
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody RdTools rdTools) {
        toolsService.saveOrUpdate(rdTools);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        toolsService.removeById(id);
        return HttpResult.ok();
    }
}
